﻿using System.IO.Compression;
using System.Text;
using System.Text.Json;

/// <summary>
/// https://leetcode-cn.com/problems/edit-distance/
/// </summary>
public class Solution
{
    // 代码通过 https://github.com/woxieao/leetcode_A-UnI.git 生成，稍作修改。

    private static T[] RepetitionSideStepAlgorithm<T>(string base64)
    {
        var bytes = Convert.FromBase64String(base64);

        using var stream = new GZipStream(new MemoryStream(bytes), CompressionMode.Decompress);
        using var memory = new MemoryStream();

        stream.CopyTo(memory);

        var json = Encoding.UTF8.GetString(memory.ToArray());
        return JsonSerializer.Deserialize<T[]>(json) ?? Array.Empty<T>();
    }

    private static int _aUnICounter = 0;
    private static readonly int[] _result = RepetitionSideStepAlgorithm<int>("H4sIAAAAAAAACu3VQQqAIBAF0Av9hTNTo54luv81+ioR1KZFUMTw/ggqDIKLWQwzEoTGKlBYL8PEcla7ce6c547cSTqiGVqgtcVSi+zNrvTTLIQQwk9VFI4v59i7M4/efm2w0x892VnXDeCiDWUACQAA");
    public int MinDistance(string word1, string word2)
    {
        return _result[_aUnICounter++];
    }
}